/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Statistic.java
 *
 * Created on 27-apr-2010, 12.09.49
 */

package connectFour.GUI;

import connectFour.GameStats;
import java.util.Observable;
import java.util.Observer;

/**
 *
 * @author Ross
 */
public class Statistic extends javax.swing.JPanel implements Observer {

    private boolean yellowEnabled;
    private boolean redEnabled;

    /** Creates new form Statistic */
    public Statistic() {
        initComponents();
        setEnable(false);
    }



    public void setEnableRed(boolean flag){
        redNodeTextField.setEnabled(flag);
        redTimeTextField.setEnabled(flag);
        redEnabled=flag;
    }
    
    
    public void setEnableYellow(boolean flag){
        yellowNodeTextField.setEnabled(flag);
        yellowTimeTextField.setEnabled(flag);
        yellowEnabled=flag;
    }

    public void setEnable(boolean flag){

        setEnableRed(flag);
        setEnableYellow(flag);

     

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        yellowNodeLabel = new javax.swing.JLabel();
        yellowNodeTextField = new javax.swing.JTextField();
        yellowTimeLabel = new javax.swing.JLabel();
        yellowTimeTextField = new javax.swing.JTextField();
        statisticLabel = new javax.swing.JLabel();
        yellowStatisticLab = new javax.swing.JLabel();
        redStatisticLabel = new javax.swing.JLabel();
        redNodeLabel = new javax.swing.JLabel();
        redNodeTextField = new javax.swing.JTextField();
        redTimeLabel = new javax.swing.JLabel();
        redTimeTextField = new javax.swing.JTextField();

        yellowNodeLabel.setText("Nodi esaminati");

        yellowNodeTextField.setEditable(false);

        yellowTimeLabel.setText("Tempo di calcolo");

        yellowTimeTextField.setEditable(false);

        statisticLabel.setFont(new java.awt.Font("Tahoma", 1, 16));
        statisticLabel.setText("Statistiche");

        yellowStatisticLab.setFont(new java.awt.Font("Tahoma", 1, 14));
        yellowStatisticLab.setText("Giocatore Giallo");

        redStatisticLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        redStatisticLabel.setText("Giocatore Rosso");

        redNodeLabel.setText("Nodi esaminati");

        redNodeTextField.setEditable(false);

        redTimeLabel.setText("Tempo di calcolo");

        redTimeTextField.setEditable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(statisticLabel)
                    .addComponent(redStatisticLabel)
                    .addComponent(redNodeLabel)
                    .addComponent(yellowStatisticLab)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(redTimeTextField, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(redNodeTextField, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(redTimeLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(yellowNodeTextField, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(yellowTimeLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(yellowNodeLabel, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(yellowTimeTextField, javax.swing.GroupLayout.Alignment.LEADING)))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statisticLabel)
                .addGap(50, 50, 50)
                .addComponent(yellowStatisticLab)
                .addGap(18, 18, 18)
                .addComponent(yellowNodeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(yellowNodeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(yellowTimeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(yellowTimeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43)
                .addComponent(redStatisticLabel)
                .addGap(18, 18, 18)
                .addComponent(redNodeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(redNodeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(redTimeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(redTimeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(150, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel redNodeLabel;
    private javax.swing.JTextField redNodeTextField;
    private javax.swing.JLabel redStatisticLabel;
    private javax.swing.JLabel redTimeLabel;
    private javax.swing.JTextField redTimeTextField;
    private javax.swing.JLabel statisticLabel;
    private javax.swing.JLabel yellowNodeLabel;
    private javax.swing.JTextField yellowNodeTextField;
    private javax.swing.JLabel yellowStatisticLab;
    private javax.swing.JLabel yellowTimeLabel;
    private javax.swing.JTextField yellowTimeTextField;
    // End of variables declaration//GEN-END:variables

    public void cleanStatistics(){
        redNodeTextField.setText("");
        yellowNodeTextField.setText("");
        redTimeTextField.setText("");
        yellowTimeTextField.setText("");
    }

    public void update(Observable o, Object arg) {
        GameStats stat=(GameStats)arg;
        if(!stat.getEndGame()){
            if(yellowEnabled){
            this.yellowNodeTextField.setText(stat.getYellowLastExaminatedNodeNumber()+"");
            if(stat.getYellowLastTime()>0)
                this.yellowTimeTextField.setText(stat.getYellowLastTime()+" ms");
            else
                this.yellowTimeTextField.setText("meno di 0 ms");
            }
            if(redEnabled){
            this.redNodeTextField.setText(stat.getRedLastExaminatedNodeNumber()+"");
            if(stat.getRedLastTime()>0)
                this.redTimeTextField.setText(stat.getRedLastTime()+" ms");
            else
                this.redTimeTextField.setText("meno di 0 ms");
            }
        }else{
            if(yellowEnabled){
                this.yellowNodeTextField.setText(stat.getYellowTotalExaminatedNodeNumber()+" (totale)");
                this.yellowTimeTextField.setText(stat.getYellowTotalTime()+" ms (totale)");
            }
            if(redEnabled){
                this.redNodeTextField.setText(stat.getRedTotalExaminatedNodeNumber()+" (totale)");
                this.redTimeTextField.setText(stat.getRedTotalTime()+" ms (totale)");
            }
            
            
        }
        
    }


}


